package com.gitee.magic.context.editor;

import java.util.List;

import com.gitee.magic.context.RestConverterEditor;
import com.gitee.magic.core.converter.AbstractConverterEditor;
import com.gitee.magic.core.json.JsonArray;

/**
 * @author start
 */
@SuppressWarnings("deprecation")
public class ListConverterEditor extends AbstractConverterEditor<String> {

	public ListConverterEditor(Class<?> prototype) {
		super(prototype);
	}

	@Override
	public void restore(Object value) {
		if (value != null) {
			setValue(RestConverterEditor.converterList(getPrototype(), new JsonArray(value.toString())));
		}
	}

	@Override
	public String converter() {
		if (getValue() == null) {
			return null;
		}
		List<?> t=(List<?>)getValue();
		return RestConverterEditor.converterJsonArray(t).toString();
	}
	
	@Override
	public Object getSource() {
		return converter();
	}

}
